#include <iostream>
#include<vector>
using namespace std;
int main() {
    long long l, r;
    long long n, q;
    cin >> n >> q;
    vector<long long> dq(n + 1);
    for (int x = 1; x <= n; x++) {
        cin >> dq[x];
        dq[x] = dq[x - 1] + dq[x];
    }
    while (q--) {
        int l, r;
        cin >> l >> r;
        cout << dq[r] - dq[l - 1] << endl;
    }
    return 0;
}
#include <iostream>
#include<vector>
using namespace std;
int main() {
    int m = 0, n = 0, q = 0;
    cin >> n >> m >> q;
    int x1 = 0, x2 = 0, y1 = 0, y2 = 0;
    vector<vector<long long>> dq(n + 1, vector<long long>(m + 1));
    for (int x = 1; x <= n; x++)
        for (int y = 1; y <= m; y++)
            cin >> dq[x][y];
    for (int x = 1; x <= n; x++)
        for (int y = 1; y <= m; y++)
            dq[x][y] = dq[x][y] + dq[x - 1][y] + dq[x][y - 1] - dq[x - 1][y - 1];
    while (q--) {
        cin >> x1 >> y1 >> x2 >> y2;
        cout << dq[x2][y2] - dq[x1 - 1][y2] - dq[x2][y1 - 1] + dq[x1 - 1][y1 - 1] << endl;
    }
    return 0;
}
